Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
mixer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_audio/mixer.h
10//! @brief Mixer.
11
12#ifndef ROC_AUDIO_MIXER_H_
13#define ROC_AUDIO_MIXER_H_
14
15#include "roc_audio/ireader.h"
16#include "roc_audio/units.h"
17#include "roc_core/list.h"
19#include "roc_core/pool.h"
20#include "roc_core/slice.h"
21
22namespace roc {
23namespace audio {
24
25//! Mixer.
26//! Mixes multiple input streams into one output stream.
27//!
28//! For example, these two input streams:
29//! @code
30//! 1, 2, 3, ...
31//! 4, 5, 6, ...
32//! @endcode
33//!
34//! are transformed into this output stream:
35//! @code
36//! 5, 7, 9, ...
37//! @endcode
38class Mixer : public IReader, public core::NonCopyable<> {
39public:
40 //! Initialize.
41 //!
42 //! @b Parameters
43 //! - @p pool is used to allocate a temporary buffer of samples
44 //! - @p frame_size defines the temporary buffer size used to read from
45 //! attached readers
46 explicit Mixer(core::BufferPool<sample_t>& pool, size_t frame_size);
47
48 //! Check if the mixer was succefully constructed.
49 bool valid() const;
50
51 //! Add input reader.
52 void add(IReader&);
53
54 //! Remove input reader.
56
57 //! Read audio frame.
58 //! @remarks
59 //! Reads samples from every input reader, mixes them, and fills @p frame
60 //! with the result.
61 virtual void read(Frame& frame);
62
63private:
64 void read_(sample_t* out_data, size_t out_sz);
65
67 core::Slice<sample_t> temp_buf_;
68
69 bool valid_;
70};
71
72} // namespace audio
73} // namespace roc
74
75#endif // ROC_AUDIO_MIXER_H_
Audio frame.
Definition: frame.h:22
Audio reader interface.
Definition: ireader.h:22
Mixer. Mixes multiple input streams into one output stream.
Definition: mixer.h:38
void remove(IReader &)
Remove input reader.
void add(IReader &)
Add input reader.
virtual void read(Frame &frame)
Read audio frame.
bool valid() const
Check if the mixer was succefully constructed.
Mixer(core::BufferPool< sample_t > &pool, size_t frame_size)
Initialize.
Intrusive doubly-linked list.
Definition: list.h:31
Base class for non-copyable objects.
Definition: noncopyable.h:23
Slice.
Definition: slice.h:23
Intrusive doubly-linked list.
float sample_t
Audio sample.
Definition: units.h:21
Root namespace.
Non-copyable object.
Pool.
Audio reader interface.
Various units used in audio processing.
Slice.